import { ApiProperty } from "@nestjs/swagger";
import { IsNotEmpty, IsOptional, IsString, Length, Matches, ValidateIf } from 'class-validator'


export class CreateUserDto {
    @ApiProperty({ description: "姓名" })
    @IsNotEmpty()//验证是否为空
    name: string;
    id: number;

    @IsOptional() // 允许字段为空
    @IsString() // 确保字段为字符串
    @Length(6, 18, { message: '密码长度必须为6-18' }) // 确保密码长度在6到18之间
    @Matches(/^(?=.*[a-zA-Z])|(?=.*[!@#$%^&*])/, {
        message: '密码必须包含一个字母或特殊字符',
    })
    password: string;

    @IsNotEmpty({ message: '用户组不能为空' })
    roleId: number;

    @IsNotEmpty({ message: '用户名不能为空' })
    userName: string;
    email: string;
    phone: string;
    gender: string;
    introduce: string;
    integral: number;
    level: number;
    address: string;

}

export class RegisterDto {
    @ValidateIf(o => o.code !== undefined && o.code !== null && o.code !== '')
    @IsNotEmpty({ message: '用户名不能为空' })
    userName: string;

    @ValidateIf(o => o.code !== undefined && o.code !== null && o.code !== '')
    @IsString()
    @Matches(/^(?=.*[a-zA-Z])|(?=.*[!@#$%^&*])/, {
        message: '密码必须包含一个字母或特殊字符',
    })
    @Length(6, 18, { message: '密码长度必须为6-18' })
    password: string;
}

export class LoginDto {
    @ApiProperty({ description: "账号", example: "admin" })
    userName: string;
    @ApiProperty({ description: "密码", example: "123456" })
    password: string;
}